package com.cnswhy.cloud.server.iot.controller;

import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.alibaba.fastjson.JSONObject;
import com.cnswhy.cloud.common.core.base.R;
import com.cnswhy.cloud.common.core.exception.BizException;
import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.common.core.utils.CnswhyUtil;
import com.cnswhy.cloud.common.rabbitmq.service.MessageService;
import com.cnswhy.cloud.common.redis.service.IdGeneratorService;
import com.cnswhy.cloud.common.redis.service.RedisService;
import com.cnswhy.cloud.server.common.entity.constant.AmqpExchange;
import com.cnswhy.cloud.server.common.entity.enumeration.MiniAppType;
import com.cnswhy.cloud.server.common.entity.enumeration.TransType;
import com.cnswhy.cloud.server.common.entity.enumeration.WalletType;
import com.cnswhy.cloud.server.common.entity.mq.UserInfoTokenMsg;
import com.cnswhy.cloud.server.core.entity.Customer;
import com.cnswhy.cloud.server.core.entity.WxUserInfo;
import com.cnswhy.cloud.server.core.service.WxUserInfoService;
import com.cnswhy.cloud.server.core.service.customer.CustomerService;
import com.cnswhy.cloud.server.core.vo.RespVo;
import com.cnswhy.cloud.server.core.wallet.WalletService;
import com.cnswhy.cloud.server.iot.config.CnswhyServerAppResourceServerConfigure;
import com.cnswhy.cloud.server.iot.dto.WxCode2SessionDTO;
import com.cnswhy.cloud.server.iot.dto.WxUserInfoDTO;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@Slf4j

@Api(tags = "微信小程序用户相关")
@Controller
@RequestMapping("/test")
public class TestProfitController {
    @Autowired
    CustomerService customerService;
    @Autowired
    WalletService walletService;
    @Autowired
    IdGeneratorService idGeneratorService;
    @ApiOperation(value = "查询openid", httpMethod = "GET")
    @ApiParam(name = "code", value = "微信Code")
    @RequestMapping(value = "/add/{amount}", method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public R<Object> add(HttpServletRequest request,@PathVariable Long amount){
        Customer customer = customerService.getById(21069154748000020L);
        walletService.add(customer.getId(), WalletType.NO_CARD, TransType.NO_CARD_SPLIT,amount,idGeneratorService.genCommonIdString());

        return R.success(null);

    }
    @ApiOperation(value = "查询openid", httpMethod = "GET")
    @ApiParam(name = "code", value = "微信Code")
    @RequestMapping(value = "/delete/{amount}", method = {RequestMethod.POST,RequestMethod.GET})

    @ResponseBody
    public R<Object> delete(HttpServletRequest request,@PathVariable Long amount){
        Customer customer = customerService.getById(21069154748000020L);
        walletService.transfer(customer.getId(),WalletType.NO_CARD,TransType.NO_CARD_TRANSFER, amount );
        return R.success(null);

    }



}
